{% extends 'easydisAPSBundle::base_template.html.twig' %}

{% block stylesheets %}
    <link rel="stylesheet" href="{{ asset('bundles/easydisAPS/css/css-template/fullcalendar.css') }}" />
{% endblock %}
    
{% block scripts %}
    <script src="{{ asset('bundles/easydisAPS/js-template/fullcalendar.min.js') }}"></script>
    <script src="{{ asset('bundles/easydisAPS/js-template/maruti.js') }}"></script>
    
   <script>
       $(document).ready(function(){
	
            unicorn.init();

            $('#add-event-submit').click(function(){
                    unicorn.add_event();
            });

            $('#event-name').keypress(function(e){
                    if(e.which == 13) {	
                            unicorn.add_event();
                    }
            });	
        });

        unicorn = {	

                // === Initialize the fullCalendar and external draggable events === //
                init: function() {	
                        // Prepare the dates
                        var date = new Date();
                        var d = date.getDate();
                        var m = date.getMonth();
                        var y = date.getFullYear();	

                        $('#fullcalendar').fullCalendar({
                                header: {
                                        left: 'prev,next',
                                        center: 'title',
                                        right: 'month,basicWeek,basicDay'
                                },
                                editable: true,
                                eventSources: [
                                    'rechercher'
                                ],
                                droppable: true, // this allows things to be dropped onto the calendar !!!
                                drop: function(date, allDay) { // this function is called when something is dropped

                                        // retrieve the dropped element's stored Event Object
                                        var originalEventObject = $(this).data('eventObject');

                                        // we need to copy it, so that multiple events don't have a reference to the same object
                                        var copiedEventObject = $.extend({}, originalEventObject);

                                        // assign it the date that was reported
                                        copiedEventObject.start = date;
                                        copiedEventObject.allDay = allDay;

                                        // render the event on the calendar
                                        // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
                                        $('#fullcalendar').fullCalendar('renderEvent', copiedEventObject, true);

                                        // is the "remove after drop" checkbox checked?

                                                // if so, remove the element from the "Draggable Events" list
                                                $(this).remove();

                                }
                        });
                        this.external_events();		
                },

                // === Adds an event if name is provided === //
                add_event: function(){
                        if($('#event-name').val() != '') {
                            var event_name = $('#event-name').val();
                            $('#external-events .panel-content').append('<div class="external-event ui-draggable label label-inverse">'+event_name+'</div>');
                            this.external_events();
                            $('#modal-add-event').modal('hide');
                            $('#event-name').val('');
                        } else {
                            this.show_error();
                        }
                },

                // === Initialize the draggable external events === //
                external_events: function(){
                        /* initialize the external events
                        -----------------------------------------------------------------*/
                        $('#external-events div.external-event').each(function() {		
                                // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
                                // it doesn't need to have a start or end
                                var eventObject = {
                                        title: $.trim($(this).text()) // use the element's text as the event title
                                };

                                // store the Event Object in the DOM element so we can get to it later
                                $(this).data('eventObject', eventObject);

                                // make the event draggable using jQuery UI
                                $(this).draggable({
                                        zIndex: 999,
                                        revert: true,      // will cause the event to go back to its
                                        revertDuration: 0  //  original position after the drag
                                });		
                        });		
                },

                // === Show error if no event name is provided === //
                show_error: function(){
                        $('#modal-error').remove();
                        $('<div style="border-radius: 5px; top: 70px; font-size:14px; left: 50%; margin-left: -70px; position: absolute;width: 140px; background-color: #f00; text-align: center; padding: 5px; color: #ffffff;" id="modal-error">Libellé requis !</div>').appendTo('#modal-add-event .modal-body');
                        $('#modal-error').delay('1500').fadeOut(700,function() {
                                $(this).remove();
                        });
                }


        };
   </script>
{% endblock %}
    
{% block style %}
    
	table {
		overflow:hidden;
		border:1px solid #d3d3d3;
		background:#fefefe;
		width:100%;
		/*margin:5% auto 0;*/
		-moz-border-radius:5px; /* FF1+ */
		-webkit-border-radius:5px; /* Saf3-4 */
		border-radius:5px;
		-moz-box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);
		-webkit-box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);
	}
	
	th {padding:18px 28px 18px; text-align:center; }
        
        td {padding:5px 5px 5px; text-align:center; }
	
	th {padding-top:18px; text-shadow: 1px 1px 1px #fff; background:#e8eaeb; color: #000;}
	
	td {border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;}
	
	tr.odd-row td {background:#f6f6f6;}
	
	td.first, th.first {text-align:left}
	
	td.last {border-right:none;}
	

	/*
        td {
		background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);
		background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe));
	}*/
	
	tr.odd-row td {
		background: -moz-linear-gradient(100% 25% 90deg, #f6f6f6, #f1f1f1);
		background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f1f1f1), to(#f6f6f6));
	}
	
	th {
		background: -moz-linear-gradient(100% 20% 90deg, #e8eaeb, #ededed);
		background: -webkit-gradient(linear, 0% 0%, 0% 20%, from(#ededed), to(#e8eaeb));
	}
	

	
	tr:first-child th.first {
		-moz-border-radius-topleft:5px;
		-webkit-border-top-left-radius:5px; /* Saf3-4 */
	}
	
	tr:first-child th.last {
		-moz-border-radius-topright:5px;
		-webkit-border-top-right-radius:5px; /* Saf3-4 */
	}
	
	tr:last-child td.first {
		-moz-border-radius-bottomleft:5px;
		-webkit-border-bottom-left-radius:5px; /* Saf3-4 */
	}
	
	tr:last-child td.last {
		-moz-border-radius-bottomright:5px;
		-webkit-border-bottom-right-radius:5px; /* Saf3-4 */
	}
        
        .larger { 
            width: 500px;
        }
        
        td.cat {
            background-color: #e7eaeb;
            font-weight: bold;
            color: #000;
        }
        
{% endblock %}


    
{% block contenu %}
    
{% for flashMessage in app.session.flashbag.get('notice') %}
    {% if flashMessage %}
            <div class="notice">
                    {{ flashMessage }}
                    <br/><br/>
            </div>
    {% endif %}
{% endfor %}

<div class="row-fluid">
    <div class="span12">				
        <div class="widget-box widget-calendar">
            <div class="widget-title">
                <span class="icon"><i class="icon-calendar"></i></span>
                <h5>Vision CP/RTT</h5>
            </div>
            <div style="margin-top : 10px; margin-left : 20px;">
            <b>Légende : <span style="color:#3a55fa">CP</span> / <span style="color:#03a606">RTT</span></b>
            </div>
            <div class="widget-content">
                <div id="fullcalendar"></div>
            </div>
        </div>
    </div>
</div>
{% endblock %}